package lib.common.use;

import java.util.ArrayList;

import android.os.AsyncTask;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.app.BaseFragment;

public class List0Fragment extends BaseFragment {

	private ArrayList<String> listdata = new ArrayList<String>();
	private ListView listview;
	private Adapter adapter = new Adapter();
	
	
	
	@Override
	public int InitLayout() {
		// TODO Auto-generated method stub
		return R.layout.fragment_list_0;
	}

	@Override
	public void InitView(View view) {
		// TODO Auto-generated method stub

		
		for (int i = 0; i < 20; i++) {
			listdata.add("" + i);
		}

		
	}

	@Override
	public void InitListener() {
		// TODO Auto-generated method stub

		listview = (ListView)mMainView.findViewById(R.id.listview);
		
		
		listview.setOnScrollListener( new OnScrollListener() {
			
			int mScrollState ;
			
			@Override
			public void onScrollStateChanged(AbsListView view, int scrollState) {
				// TODO Auto-generated method stub
				
				switch(scrollState){
				case OnScrollListener.SCROLL_STATE_IDLE://空闲状态
							
					break;
				case OnScrollListener.SCROLL_STATE_FLING://滚动状态
					
					
					break;
				case OnScrollListener.SCROLL_STATE_TOUCH_SCROLL://触摸后滚动
						
					break;
				}
				
			}
			
			@Override
			public void onScroll(AbsListView view, int firstVisibleItem,
					int visibleItemCount, int totalItemCount) {
				// TODO Auto-generated method stub
				
				String str = (String)listview.getItemAtPosition(firstVisibleItem);
				ShowToast(str);
				
				
			}
		});
		
		
		
	}

	@Override
	public void InitProcess() {
		// TODO Auto-generated method stub

		listview.setAdapter(adapter);
		
		
		
	}
	
	
	
	
	class Adapter extends BaseAdapter
	{

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return listdata.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return listdata.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			// TODO Auto-generated method stub
			
			convertView = mInflater.inflate(R.layout.layout_list_0, null);
			TextView tv_title =(TextView)convertView.findViewById(R.id.tv_title);
			tv_title.setText( ""+listdata.get(position) );
			
			return convertView;
		}
		
	};
	
	
	
	
	
	private class GetDataTask extends AsyncTask<Void, Void, String[]> {
		@Override
		protected String[] doInBackground(Void... params) {
			// Simulates a background job.
			try {
				Thread.sleep(4000);
			} 
			catch (InterruptedException e) {
			}
			return null;
		}

		@Override
		protected void onPostExecute(String[] result) {
			// Do some stuff here
			// Call onRefreshComplete when the list has been refreshed.
			super.onPostExecute(result);
		}

	}
	
	

}
